package com.数据结构与算法.迭代Iteration;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class addDemo01 {

    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(System.in);
        System.out.println("please input num:");
        int num = getInt();
//        int num = scanner.nextInt();

        addDemo01 addDemo01 = new addDemo01();

        System.out.println(addDemo01.AutoAdd(num));

//        System.out.println((76288+175104+4322)/1024 + "m");
        System.out.println(addDemo01.AutoAdd1(num));



    }




    public int AutoAdd(int n){
        int total = 0;
        while (n>0){
            total += n;
            --n;
        }
        return total;
    }


    public int AutoAdd1(int n){
            int total;
        if (n == 1) {
            return 1;
        }else {
            return  (n + AutoAdd1(n-1));
        }
    }



    public static String  getString() throws IOException {
        String x;
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader bis = new BufferedReader(isr);

        x = bis.readLine();


        return x;
    }

    public static int getInt() throws IOException {
        String s = getString();
        return  Integer.valueOf(s);
    }


}
